home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / tprint.arc / TESTPRN.PAS < prev   
Pascal/Delphi Source File  |  1991-04-10  |  2KB  |  91 lines

  1. PROGRAM TestPrn;
  2. {-- Sample program using the printer unit --}
  3.  
  4. Uses wObjects,winProcs,pDevice,stdDlgs,WinTypes;
  5. const
  6.   cmSetPrint = 1;
  7.   cmPrintFile = 2;
  8.  
  9. TYPE
  10.   tTestApp = object(tApplication)
  11.     procedure InitMainWindow; virtual;
  12.   end;
  13.  
  14.   pPrnWindow = ^tPrnWindow;
  15.   tPrnWindow = object(tWindow)
  16.     printer: pPrinter;
  17.     constructor Init(aParent: pWindowsObject;aTitle: pChar);
  18.     procedure   setPrinter(var msg:tMessage);virtual cm_first + cmSetPrint;
  19.     procedure   filePrint(var msg: tMessage);virtual cm_first + cmPrintFile;
  20.   end;
  21.   pathStr = array[0..64] of Char;
  22.  
  23.  
  24. {$R test.res}
  25.  
  26. procedure tPrnWindow.setPrinter(var msg:tMessage);
  27. begin
  28.   printer := new(pPrinter,Init);
  29.   printer^.prnDeviceMode(hWindow);
  30.   dispose(printer,Done);
  31. End;
  32.  
  33. Function fileIsOpen(var t: Text;f: pathStr): Boolean;
  34. var
  35.   ioCode: integer;
  36. Begin
  37. {$I-}
  38.   assign(t,f);
  39.   reset(t);
  40.   ioCode := ioResult;
  41.   fileIsOpen := (ioCode = 0);
  42. {$I+}
  43. end;
  44.  
  45. procedure tPrnWindow.filePrint(var msg: tMessage);
  46. {-- Gets a file name from the user, and prints it out. (the file, not
  47.     the file name --}
  48. var
  49.   fName: pathStr;
  50.   textFile: Text;
  51.   tLine: array[0..79] of char;
  52.  
  53. Begin
  54.   fName[0] := ' ';
  55.   if (Application^.ExecDialog(new(pInputDialog,Init(@self,'File to Print',
  56.          'Enter File Name: ',fName,SizeOf(fName)))) = id_OK) then begin
  57.     if (FileIsOpen(textFile,fName)) then begin
  58.       printer := new(pPrinter,Init);          {init the printer object}
  59.       if printer^.Start('PrnTest',hWindow) then begin  {start the printer}
  60.         while not eof(textFile) do begin
  61.           readln(textFile,tLine);
  62.           printer^.TextLine(tLine);     {send each line to the printer object}
  63.         End;
  64.         close(textFile);
  65.         printer^.Finish;                {finish the print job}
  66.         dispose(printer,Done);
  67.       End;
  68.     End;
  69.   End;
  70. end;
  71.  
  72. constructor tPrnWindow.Init(aParent: pWindowsObject;aTitle: pChar);
  73. begin
  74.   tWindow.Init(aParent,aTitle);
  75.   attr.Menu := loadMenu(hInstance,pChar(100));
  76. end;
  77.  
  78. Procedure tTestApp.InitMainWindow;
  79. Begin
  80.   MainWindow := new(pPrnWindow,init(nil,'Printer Test'));
  81. End;
  82.  
  83.  
  84. var
  85.   tApp: tTestApp;
  86.  
  87. Begin
  88.   tApp.Init('Printer Test');
  89.   tApp.Run;
  90.   tApp.Done;
  91. End.